<%@page language="java" contentType="text/html; charset=utf-8"	pageEncoding="utf-8"%>
<%
	String typeId = (String) request.getAttribute("typeId");
%>
<html>
<head>

<script type="text/javascript">
	var typeId=<%=typeId%>;
	var listUrl = "rest/dictList.do?typeId="+typeId;

	$(document).ready(
					function() {
						$("#submit-search").click(function() {
							$('#dg').datagrid({
								queryParams : form2Json("fms")
							}); //点击搜索
						});

						$("#dg")
								.datagrid(
										{
											loadMsg : '数据加载中....',
											//title : '字典管理',
											//height : document.body.clientHeight - 165,
											width : '100%',
											url : listUrl,
											method : 'get',
											loadFilter : function(result) {
												if (result.retCode == '0000') {
													return result.data;
												} else {
													return result.retMsg;
												}
											},
											nowrap : false,
											striped : true,
											sortOrder : 'desc',
											remoteSort : false,
											rownumbers : true,
											pagination : true,
											pageList : [ 10, 15, 20, 25 ],
											fitColumns : true,
											frozenColumns : [ [ {
												field : 'id',
												checkbox : true
											}, {
												title : '字典编号',
												field : 'id',
												width : 0,
												hidden : 'true'
											} ] ],
											columns : [ [
													{
														field : 'dictName',
														title : '字典名称',
														width : 210
													},
													{
														field : 'dictValue',
														title : '字典值',
														width : 100
													},
													{
														field : 'dictDesc',
														title : '备注',
														width : 100
													}

											] ]
										});// end datagrid
						//设置分页控件
						var p = $('#dg').datagrid('getPager');
						$(p)
								.pagination(
										{
											pageSize : 10,//每页显示的记录条数，默认为10
											pageList : [ 10, 15, 20, 25 ],//可以设置每页记录条数的列表
											beforePageText : '第',//页数文本框前显示的汉字
											afterPageText : '页    共 {pages} 页',
											displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录',
											onBeforeRefresh : function() {
												$(this).pagination('loading');
												$(this).pagination('loaded');
											}

										});//end pagination

					});//end ready
	

	function add() {
		var url = "dict/add.do?typeId="+typeId;
		$.get(url, {}, function(data) {
			$("#center").empty();
			$("#center").html(data);
			$.parser.parse($("#center"));
		});
	}

	function edit() {
		var rows = $('#dg').datagrid('getSelections');
		if (rows.length != 1) {
			$.messager.alert('操作提示', "请先选择一条要编辑的信息！");
			return;
		}

		var row = $('#dg').datagrid('getSelected');
		var id = row.id;

		var url = "dict/edit.do?id=" + id+"&typeId="+typeId;
		$.get(url, row, function(data) {
			$("#center").empty();
			$("#center").html(data);
			$.parser.parse($("#center"));
		});

	}

	function removes() {
		var array = $('#dg').datagrid('getSelections');
		var ids = new Array();
		for ( var i = 0; i < array.length; i++) {//组成一个字符串，ID主键之间用逗号隔开
			ids[i] = array[i].id;
		}
		ids = ids.join(',');

		if (array != "") {
			$.messager.defaults = {
				ok : "确定",
				cancel : "取消"
			};
			$.messager.confirm('操作提示', '是否要删除该信息？', function(r) {
				if (r) {
					$.post('rest/dictDel.do', {
						ids : ids
					}, function(response) {

						if (response.success == "false") {
							$.messager.alert('操作提示', "删除失败", 'error');
						} else {
							$('#dg').datagrid('reload');
							$.messager.alert('操作提示', "删除成功", 'info');
						}
					});
				}
			});
		} else {
			$.messager.alert('操作提示', "请先选择要删除的信息！");
		}

	};

	
	
	var superList="dictType/index.do";
	function back(url) {
		$.get(url, {}, function(data) {
			$("#center").empty();
			$("#center").html(data);
			$.parser.parse($("#center"));
		});
	}
</script>
</head>
<body>
	<div class="linkbar"><a>系统</a>/<a>字典类型管理</a>/<a>字典管理</a></div>
	<div id="search" class="formtoolbar"  style="width:100%">
			<div split="false" style="width:100%">
			<form id="fms" method="post" novalidate>

				<i>字典名称</i> <input name="typeName" class="easyui-validatebox" /> 
				
				<i>字典值</i>	<input name="typeDesc" class="easyui-validatebox" /> 
				<a	id="submit-search" class="easyui-linkbutton">查询</a>


			</form>
		</div>
		</div> 
	<div class="clear"></div>
	<div id="dg" toolbar="#toolbar"></div>

	<div id="toolbar">
		<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"	onclick="add()">添加</a> 
		<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit()">编辑</a> 
		<a href="#"	class="easyui-linkbutton" iconCls="icon-remove" plain="true"	onclick="removes()">删除</a>
		<a href="#"	class="easyui-linkbutton" iconCls="icon-remove" plain="true"	onclick="back(superList)">返回上级</a>
	</div>
</body>
</html>